package cn.jxwazx.sheinspringboot.utils;

import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.BooleanUtil;
import org.dromara.hutool.core.util.ObjUtil;

import java.util.Collection;

/**
 * @author LoveHuahua
 * @date 2022年03月26日 16:02
 * @description believe in yourself
 */
public class CheckUtil {


    /**
     * 如果是空 那么抛出异常
     *
     * @param collection 集合
     * @param exception  异常
     */
    public static void checkNotEmpty(Collection<?> collection, RuntimeException exception) {
        if (CollUtil.isEmpty(collection)) {
            throw exception;
        }
    }


    public static void checkNotNull(Object object, RuntimeException exception) {
        checkTrue(ObjUtil.isNotNull(object), exception);
    }

    /**
     * object不为空抛出异常
     * @param object
     * @param exception
     */
    public static void checkNull(Object object, RuntimeException exception) {
        checkTrue(ObjUtil.isNull(object), exception);
    }

    /**
     * 检测str 不是默认
     *
     * @param exception 异常
     * @param str       str
     */
    public static void checkStrNotBlank(String str, RuntimeException exception) {
        checkTrue(StrUtil.isNotBlank(str), exception);
    }

    public static void checkTrue(Boolean condition, RuntimeException exception) {
        if (!BooleanUtil.isTrue(condition)) {
            throw exception;
        }
    }


    public static void checkFalse(boolean condition, RuntimeException exception) {
        checkTrue(!condition, exception);
    }


}
